from ctaf_core.ctaf_objects.base_bundle import BaseBundle
from ctaf_core.ctaf_objects.base_data_objects import LogEventData
from ctaf_core.ctaf_objects.base_event import BaseEvent
from ctaf_core.ctaf_objects.base_exception import CTAFbaseException
from ctaf_core.log_trace_bundle.logging import LogRecorder, LoggerFactory


class LogTraceBundle(BaseBundle):

    def __init__(self):
        super().__init__("LogTraceBundle")
        self.log_recorder: LogRecorder = LoggerFactory.get_logger()

    def load_bundle(self):
        pass

    def debug(self, msg: str = None, exception: CTAFbaseException = None):
        self.log_recorder.write_debug_log(msg, exception)

    def info(self, msg: str = None, exception: CTAFbaseException = None):
        self.log_recorder.write_info_log(msg, exception)

    def warn(self, msg: str = None, exception: CTAFbaseException = None):
        self.log_recorder.write_warn_log(msg, exception)

    def error(self, msg: str = None, exception: CTAFbaseException = None):
        self.log_recorder.write_error_log(msg, exception)

    def critical(self, msg: str = None, exception: CTAFbaseException = None):
        self.log_recorder.write_critical_log(msg, exception)

    def process_event(self, event: BaseEvent):
        log_event_data: LogEventData = event.get_event_data()
        self.info(log_event_data.get_event_data_in_str())

    def unload_bundle(self):
        pass

